<?php
/*
 * @FilePath: \crm\application\crm\model\auth\Admin.php
 */

namespace app\crm\model\auth;

use think\Model;

class Admin extends Model
{
    protected $autoWriteTimestamp = true;

    protected $table = 'yd_crm_admin';

    protected $auto = [
        'account'
    ];
    public function setAccountAttr()
    {
        $account = $this->field('account')->order('id desc')->find();
        if (!empty($account)) {
            $number = $account['account'] + 1;
            substr($account['account'], -1, 1) == 3 && $number = $account['account'] + 2;
            return $number;
        } else {
            return '9501';
        }
    }

    public function role()
    {
        return $this->belongsTo('Role', 'role_id', 'id');
    }
}
